import { getApplicationsApi } from '@/apis/modules/application'

export default function useConfig() {
  const appList = ref<LabelValue[]>([])

  async function getApplications() {
    const res = await getApplicationsApi({ limit: 500 })
    appList.value = (res.list || []).map((item) => {
      return {
        label: item.name!,
        value: item.app_id!,
      }
    })
  }

  const tableColumns = buildColumns([
    {
      title: '实例名称',
      dataIndex: 'name',
    },
    {
      title: '所属应用',
      dataIndex: 'app_id',
      slotName: 'appId',
    },
    {
      title: '地址池来源',
      dataIndex: 'address_pool_type',
      slotName: 'addressPoolType',
    },
    {
      title: '接入域名',
      dataIndex: 'domain_name',
      slotName: 'domainName',
    },
    {
      title: 'TTL',
      dataIndex: 'ttl',
      slotName: 'ttl',
    },
    {
      title: '策略数',
      dataIndex: 'strategy_count',
    },
    {
      title: '创建时间 ',
      dataIndex: 'created_at',
      format: 'date-time',
      sortable: sortableSettings,
    },
    {
      title: '操作',
      fixed: 'right',
      slotName: 'actions',
      width: 80,
      cellClass: 'actions-cell',
    },
  ])

  onMounted(getApplications)

  return {
    appList,
    tableColumns,
  }
}
